<cfset dirStr = "D:/workspaces/nuuvo-flex/FlexLocale/sources/sunjdk/" />
<cfset outDir = "D:/workspaces/nuuvo-flex/FlexLocale/uk/co/riait/as3/locale/providers/" />

<cffunction name="dump"><cfdump var="#arguments#" /><cfabort /></cffunction>

<cfdirectory action="list" directory="#dirStr#" name="dir"/>

<cfset arr_classes = arrayNew(1) />

<cfloop query="dir">
	
	<cfif lCase(type) eq "file" and find("_", name)>
		<cffile action="read" file="#dirStr##name#" variable="cnt" charset="utf-8" />
		<cfset data = xmlParse( cnt ) />
		<cfset className = replace(name,".xml","") />
		<cfset arr_classes[arrayLen(arr_classes)+1] = "Provider_" & className />
		<cfscript>
			strOut = "/*" & chr(10);
			strOut &= " * Copyright (c) 2007 RIA IT (http://riait.co.uk/)" & chr(10);
			strOut &= " * " & chr(10);
			strOut &= " * Permission is hereby granted, free of charge, to any person obtaining a copy" & chr(10);
			strOut &= " * of this software and associated documentation files (the 'Software'), to deal" & chr(10);
			strOut &= " * in the Software without restriction, including without limitation the rights" & chr(10);
			strOut &= " * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" & chr(10);
			strOut &= " * copies of the Software, and to permit persons to whom the Software is" & chr(10);
			strOut &= " * furnished to do so, subject to the following conditions:" & chr(10);
			strOut &= " * " & chr(10);
			strOut &= " * The above copyright notice and this permission notice shall be included in" & chr(10);
			strOut &= " * all copies or substantial portions of the Software." & chr(10);
			strOut &= " * " & chr(10);
			strOut &= " * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" & chr(10);
			strOut &= " * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," & chr(10);
			strOut &= " * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" & chr(10);
			strOut &= " * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" & chr(10);
			strOut &= " * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," & chr(10);
			strOut &= " * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN" & chr(10);
			strOut &= " * THE SOFTWARE." & chr(10);
			strOut &= " */" & chr(10);
			strOut &= "package uk.co.riait.as3.locale.providers {" & chr(10);
			strOut &= "	public class Provider_" & className & " extends ProviderBase implements ILocaleProvider {" & chr(10);
			strOut &= "		private var _currencyMarker:String = '�';" & chr(10);
			
			// language identity:
			strOut &= "		public function get language():String {" & chr(10);
			strOut &= "			return '" & xmlSearch(data,"//identity/language").get(0).xmlAttributes.type & "';" & chr(10);
			strOut &= "		}" & chr(10);
			strOut &= "		public function get territory():String {" & chr(10);
			strOut &= "			return '" & xmlSearch(data, "//identity/territory").get(0).xmlAttributes.type & "';" & chr(10);
			strOut &= "		}" & chr(10);
		// pattern chars:
			_set = xmlSearch(data, "//dates/localizedPatternChars");
			strOut &= "		public function get datesLocalizedPatternChars():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// minimal days in first week:
			_set = xmlSearch(data, "//dates/calendars/calendar/week/minDays");
			strOut &= "		public function get minimalDaysInFirstWeek():Number {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return " & _set.get(0).xmlAttributes.count & ";" & chr(10);
			else
				strOut &= "			return 0;" & chr(10);
			strOut &= "		}" & chr(10);
		// first day ofthe week:
			_set = xmlSearch(data, "//dates/calendars/calendar/week/firstDay");
			strOut &= "		public function get firstDayOfTheWeek():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlAttributes.day & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// am:
			_set = xmlSearch(data, "//dates/calendars/calendar/am");
			strOut &= "		public function get am():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// pm:
			_set = xmlSearch(data, "//dates/calendars/calendar/pm");
			strOut &= "		public function get pm():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// era1:
			_set = xmlSearch(data, "//dates/calendars/calendar/eras/eraAbbr/era[attribute::type='1']");
			strOut &= "		public function get era1():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// era0:
			_set = xmlSearch(data, "//dates/calendars/calendar/eras/eraAbbr/era[attribute::type='0']");
			strOut &= "		public function get era0():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// dateTimeFormat:
			_set = xmlSearch(data, "//dates/calendars/calendar/dateTimeFormats/dateTimeFormatLength/dateTimeFormat/pattern");
			strOut &= "		public function get dateTimeFormat():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// date mask full:
			_set = xmlSearch(data, "//dates/calendars/calendar/dateFormats/dateFormatLength[attribute::type='full']/dateFormat/pattern");
			strOut &= "		public function get dateMaskFull():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// date mask long:
			_set = xmlSearch(data, "//dates/calendars/calendar/dateFormats/dateFormatLength[attribute::type='long']/dateFormat/pattern");
			strOut &= "		public function get dateMaskLong():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// date mask medium:
			_set = xmlSearch(data, "//dates/calendars/calendar/dateFormats/dateFormatLength[attribute::type='medium']/dateFormat/pattern");
			strOut &= "		public function get dateMaskMedium():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// date mask short:
			_set = xmlSearch(data, "//dates/calendars/calendar/dateFormats/dateFormatLength[attribute::type='short']/dateFormat/pattern");
			strOut &= "		public function get dateMaskShort():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// time mask full:
			_set = xmlSearch(data, "//dates/calendars/calendar/timeFormats/timeFormatLength[attribute::type='full']/timeFormat/pattern");
			strOut &= "		public function get timeMaskFull():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// time mask long:
			_set = xmlSearch(data, "//dates/calendars/calendar/timeFormats/timeFormatLength[attribute::type='long']/timeFormat/pattern");
			strOut &= "		public function get timeMaskLong():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// time mask medium:
			_set = xmlSearch(data, "//dates/calendars/calendar/timeFormats/timeFormatLength[attribute::type='medium']/timeFormat/pattern");
			strOut &= "		public function get timeMaskMedium():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// time mask short:
			_set = xmlSearch(data, "//dates/calendars/calendar/timeFormats/timeFormatLength[attribute::type='short']/timeFormat/pattern");
			strOut &= "		public function get timeMaskShort():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// decimal:
			_set = xmlSearch(data, "//numbers/symbols/decimal");
			strOut &= "		public function get decimal():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// group:
			_set = xmlSearch(data, "//numbers/symbols/group");
			strOut &= "		public function get group():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & replace(_set.get(0).xmlText,"'","\'","all") & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// list:
			_set = xmlSearch(data, "//numbers/symbols/list");
			strOut &= "		public function get list():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// percent sign:
			_set = xmlSearch(data, "//numbers/symbols/percentSign");
			strOut &= "		public function get percentSign():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// native zero:
			_set = xmlSearch(data, "//numbers/symbols/nativeZeroDigit");
			strOut &= "		public function get nativeZeroDigit():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// pattern digit:
			_set = xmlSearch(data, "//numbers/symbols/patternDigit");
			strOut &= "		public function get patternDigit():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// minus sign:
			_set = xmlSearch(data, "//numbers/symbols/minusSign");
			strOut &= "		public function get minusSign():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// exponential:
			_set = xmlSearch(data, "//numbers/symbols/exponential");
			strOut &= "		public function get exponential():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// per mille:
			_set = xmlSearch(data, "//numbers/symbols/perMille");
			strOut &= "		public function get perMille():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// infinity:
			_set = xmlSearch(data, "//numbers/symbols/infinity");
			strOut &= "		public function get infinity():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// NaN:
			_set = xmlSearch(data, "//numbers/symbols/nan");
			strOut &= "		public function get nan():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		
		// decimal formats:
			_set = xmlSearch(data, "//numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern");
			strOut &= "		public function get decimalFormat():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// percent formats:
			_set = xmlSearch(data, "//numbers/percentFormats/percentFormatLength/percentFormat/pattern");
			strOut &= "		public function get percentFormat():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		// currency formats:
			_set = xmlSearch(data, "//numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern");
			strOut &= "		public function get currencyFormat():String {" & chr(10);
			if ( arrayLen(_set) > 0 )
				strOut &= "			return '" & _set.get(0).xmlText & "';" & chr(10);
			else
				strOut &= "			return null;" & chr(10);
			strOut &= "		}" & chr(10);
		
		
		// set of languages:
			_set = xmlSearch(data.xmlRoot, "//localeDisplayNames/languages/language");
			strOut &= "		private static const _languages:Object = {" & chr(10);
			for ( i=1; i lte arrayLen(_set); i=i+1 )
			{
				strOut &= "			" & ucase(_set[i].xmlAttributes.type) & ": '" & replace(_set[i].xmlText,"'","\'","all") & "'";
				if ( i < arrayLen( _set ) ) strOut &= ",";
				strOut &= chr(10);
			}
			strOut &= "		};" & chr(10);
		// set of territories:
			_set = xmlSearch(data.xmlRoot, "//localeDisplayNames/territories/territory");
			strOut &= "		private static const _territories:Object = {" & chr(10);
			for ( i=1; i lte arrayLen(_set); i=i+1 )
			{
				strOut &= "			" & _set[i].xmlAttributes.type & ": '" & replace(_set[i].xmlText,"'","\'","all") & "'";
				if ( i < arrayLen( _set ) ) strOut &= ",";
				strOut &= chr(10);
			}
			strOut &= "		};" & chr(10);

		// set of currencies:
			_set = xmlSearch(data.xmlRoot, "//numbers/currencies/currency");
			strOut &= "		private static const _currencies:Object = {" & chr(10);
			for ( i=1; i lte arrayLen(_set); i=i+1 )
			{
				strOut &= "			" & _set[i].xmlAttributes.type & ": '" & replace(_set[i].xmlChildren[1].xmlText,"'","\'","all") & "'";
				if ( i < arrayLen( _set ) ) strOut &= ",";
				strOut &= chr(10);
			}
			strOut &= "		};" & chr(10);

		// set of long month names:
			_set = xmlSearch(data.xmlRoot, "//dates/calendars/calendar/months/monthContext/monthWidth[attribute::type='wide']/month");
			strOut &= "		private static const _monthNamesLong:Array = [" & chr(10);
			for ( i=1; i lte 12; i=i+1 )
			{
				try { strOut &= "			'" & replace(_set[i].xmlText,"'","\'","all") & "'"; }
				catch ( any e ) {strOut &= "			null"; }
				if ( i < 12 ) strOut &= ",";
				strOut &= chr(10);
			}
			strOut &= "		];" & chr(10);
		// set of short month names:
			_set = xmlSearch(data.xmlRoot, "//dates/calendars/calendar/months/monthContext/monthWidth[attribute::type='abbreviated']/month");
			strOut &= "		private static const _monthNamesAbbr:Array = [" & chr(10);
			for ( i=1; i lte 12; i=i+1 )
			{
				try { strOut &= "			'" & replace(_set[i].xmlText,"'","\'","all") & "'"; }
				catch ( any e ) {strOut &= "			null"; }
				if ( i < 12 ) strOut &= ",";
				strOut &= chr(10);
			}
			strOut &= "		];" & chr(10);
		// set of long day names:
			_set = xmlSearch(data.xmlRoot, "//dates/calendars/calendar/days/dayContext/dayWidth[attribute::type='wide']/day");
			strOut &= "		private static const _dayNamesLong:Array = [" & chr(10);
			for ( i=1; i lte 7; i=i+1 )
			{
				try { strOut &= "			'" & replace(_set[i].xmlText,"'","\'","all") & "'"; }
				catch ( any e ) {strOut &= "			null"; }
				if ( i < 7 ) strOut &= ",";
				strOut &= chr(10);
			}
			strOut &= "		];" & chr(10);
		// set of short day names:
			_set = xmlSearch(data.xmlRoot, "//dates/calendars/calendar/days/dayContext/dayWidth[attribute::type='abbreviated']/day");
			strOut &= "		private static const _dayNamesAbbr:Array = [" & chr(10);
			for ( i=1; i lte 7; i=i+1 )
			{
				try { strOut &= "			'" & replace(_set[i].xmlText,"'","\'","all") & "'"; }
				catch ( any e ) {strOut &= "			null"; }
				if ( i < 7 ) strOut &= ",";
				strOut &= chr(10);
			}
			strOut &= "		];" & chr(10);
		// implementations:
		strOut &= "		public function get currencies():Object { return _currencies; }" & chr(10);
		strOut &= "		public function get dayNamesAbbr():Array { return _dayNamesAbbr; }" & chr(10);
		strOut &= "		public function get dayNamesLong():Array { return _dayNamesLong; }" & chr(10);
		strOut &= "		public function get languages():Object { return _currencies; }" & chr(10);
		strOut &= "		public function get monthNamesAbbr():Array { return _dayNamesAbbr; }" & chr(10);
		strOut &= "		public function get monthNamesLong():Array { return _dayNamesLong; }" & chr(10);
		strOut &= "		public function get territories():Object { return _territories; }" & chr(10);

			strOut &= "	}" & chr(10);
			strOut &= "}" & chr(10);
		</cfscript>
		<cffile action="write" file="#outDir#Provider_#className#.as" output="#strOut#" charset="utf-8" />

	</cfif>

</cfloop>
<!---
	Generate classes library: --->
<cfscript>
	strOut = "/*" & chr(10);
	strOut &= " * Copyright (c) 2007 RIA IT (http://riait.co.uk/)" & chr(10);
	strOut &= " * " & chr(10);
	strOut &= " * Permission is hereby granted, free of charge, to any person obtaining a copy" & chr(10);
	strOut &= " * of this software and associated documentation files (the 'Software'), to deal" & chr(10);
	strOut &= " * in the Software without restriction, including without limitation the rights" & chr(10);
	strOut &= " * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" & chr(10);
	strOut &= " * copies of the Software, and to permit persons to whom the Software is" & chr(10);
	strOut &= " * furnished to do so, subject to the following conditions:" & chr(10);
	strOut &= " * " & chr(10);
	strOut &= " * The above copyright notice and this permission notice shall be included in" & chr(10);
	strOut &= " * all copies or substantial portions of the Software." & chr(10);
	strOut &= " * " & chr(10);
	strOut &= " * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" & chr(10);
	strOut &= " * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," & chr(10);
	strOut &= " * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" & chr(10);
	strOut &= " * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" & chr(10);
	strOut &= " * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," & chr(10);
	strOut &= " * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN" & chr(10);
	strOut &= " * THE SOFTWARE." & chr(10);
	strOut &= " */" & chr(10);
	strOut &= "package uk.co.riait.as3.locale.providers {" & chr(10);
	strOut &= "	public class ProviderLibrary {" & chr(10);
	for (i=1; i<arrayLen(arr_classes); i=i+1)
		strOut &= "		private var _cls" & i & ":" & arr_classes[i] & " = new " & arr_classes[i] & "();" & chr(10);
	strOut &= "	}" & chr(10);
	strOut &= "}" & chr(10);
</cfscript>
<cffile action="write" file="#outDir#ProviderLibrary.as" output="#strOut#" charset="utf-8" />